/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.accessorgen;

import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.cef.core.data.ValueObjAccessor;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.common.MediatePropertyInfo;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.AccessorInitializeNestedGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.NestedAccessorCtorGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.NestedAccessorInitializeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.ReadOnlyAcceptChangeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.base.AccessorInitializeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.BaseDataGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.EntityGeneratorContext;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.ChildPropGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.SimpleUdtDataValuePropGenerator;
import com.inspur.edp.das.commonmodel.IGspCommonObject;
import com.inspur.edp.udt.designtime.api.entity.SimpleDataTypeDef;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier;

public class ReadOnlyNestedAcsGenerator extends ReadonlyBaseAcsGenerator
{
	public ReadOnlyNestedAcsGenerator(EntityGeneratorContext parContext, IGspCommonDataType node, MediateType targetInterfaceType) {
		super(parContext, node, targetInterfaceType);
	}

	public ReadOnlyNestedAcsGenerator(EntityGeneratorContext parContext, String nodeCode, MediateType targetInterfaceType) {
		super(parContext, nodeCode, targetInterfaceType);
	}

	protected AccessorClassGenContext getReadonlyAccClassGenContext (){return (AccessorClassGenContext)super.getContext();}

	@Override
	protected ClassGeneratorContext createClassInfoContext(){return new AccessorClassGenContext(ParentContext);}

	@Override
	protected ArrayList<Modifier.ModifierKeyword> getAccessModifier() {
		ArrayList<Modifier.ModifierKeyword> list=new ArrayList<>();
		list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
		return list;
	}

	@Override
	protected TypeInfo setParentClass() {
		return new TypeInfo(ValueObjAccessor.class.getTypeName());
	}

	@Override
	protected void addAcsExtendMethod(java.util.ArrayList<ClassMethodGenerator> methodGens)
	{
		super.addAcsExtendMethod(methodGens);
		ClassMethodGenerator acceptChangeGen = getAcceptChangeGenerator();
		methodGens.add(acceptChangeGen);
		methodGens.add(new AccessorInitializeNestedGen(getReadonlyAccClassGenContext(),NodeCode, PropertyInfos, TargetInterfaceType, null, true));
	}

	@Override
	protected BaseDataGenerator getChildsGenerator(EntityGeneratorContext parContext,
			IGspCommonObject node)
	{
		return null;
	}

	@Override
	protected ChildPropGenerator getChildPropGenerator(String childCode,
			MediatePropertyInfo propertyInfo, String privatePropName)
	{
		return null;
	}


	@Override
	public AccessorInitializeGen getInitilizeGenerator(){return  new NestedAccessorInitializeGen();}

		///#endregion

	private ClassMethodGenerator getAcceptChangeGenerator()
	{
		return new ReadOnlyAcceptChangeGen();
	}
	@Override
	protected java.util.ArrayList<ClassMethodGenerator> createConstructorGenerators()
	{

		java.util.ArrayList<ClassMethodGenerator> list = super.createConstructorGenerators();
		if (list == null)
		{
			list = new java.util.ArrayList<ClassMethodGenerator>();
		}
		list.add(new NestedAccessorCtorGenerator(getName(), TargetInterfaceType));
		return list;
	}

	@Override
	protected void addExtendPropertyGenerator(java.util.ArrayList<ClassPropertyGenerator> proGenerators)
	{
		super.addExtendPropertyGenerator(proGenerators);
		if(Node instanceof SimpleDataTypeDef) {
			proGenerators.add(new SimpleUdtDataValuePropGenerator((SimpleDataTypeDef) Node));
		}
	}
}
